import { Color } from 'https://unpkg.com/three/build/three.module.js';
import { initShaders } from '../jsm/Utils.js';
import lib from '../jsm/ThreeLib.js';
import Poly from '../jsm/Poly.js'
import Sky from '../jsm/Sky.js'
import ShapeGeo from '../jsm/ShapeGeo.js';

window.onload = function () {

    const backColor = new Color("rgba(0,0,0,1)");

    const canvas = document.getElementById("canvas");
    canvas.width = window.innerWidth;
    canvas.height = window.innerHeight;

    const gl = canvas.getContext("webgl");
    //开启颜色合成,才会有透明度的感觉
    gl.enable(gl.BLEND);
    gl.blendFunc(gl.SRC_ALPHA, gl.ONE_MINUS_SRC_ALPHA);

    //初始化着色器
    initShaders(gl,
        document.querySelector("#vertexShader").innerText,
        document.querySelector("#fragmentShader").innerText);
    lib.clearCanvas(gl, new Color("rgba(0,0,0,1)"), 1);


    let u_m2 = gl.getUniformLocation(gl.program, 'u_m2');

    let angle = 0.5;
    let u_cos = Math.cos(angle);
    let u_sin = Math.sin(angle);
    let u_matrix = [
        u_cos, u_sin,
        -u_sin, u_cos
    ];


    let poly = new Poly({
        gl: gl,
        vertices: [
            -0.2, 0,
            0.2, 0,
            0.0, 0.3,
        ]
    })

    gl.uniformMatrix2fv(u_m2, false, u_matrix)

    poly.draw(["TRIANGLES"]);


}